package main

import (
	"flag"
	"fmt"
	. "leaf/common"
	"leaf/core/tool"
	"leaf/server/auth"
	"leaf/server/logic"
	"leaf/server/match"
	"leaf/server/pvp"
	"log"
	"net/http"
	_ "net/http/pprof"

	"strings"
)

var closeSig = make(chan bool, 1)

func main() {
	go func() {
		log.Println(http.ListenAndServe("0.0.0.0:6060", nil))
	}()

	path := flag.String("f", "conf/logic_2001.json", "run config")
	flag.Parse()
	argStr := *path
	index := strings.LastIndex(argStr, "/")
	if index >= 0 {
		argStr = argStr[index+1:]
	}
	argStr = strings.TrimSuffix(argStr, ".json")
	args := strings.Split(argStr, "_")
	if len(args) != 2 {
		panic(fmt.Sprintf("path:%v agrs err", path))
	}

	if SRV_TYPE_MAP[args[0]] != int32(tool.Atoi(args[1]))/1000 {
		panic(fmt.Sprintf("path:%v agrs err", path))
	}

	switch args[0] {
	case ServType_Name_Auth:
		auth.Run(*path)
	case ServType_Name_Logic:
		logic.Run(*path)
	case ServType_Name_Match:
		match.Run(*path)
	case ServType_Name_Pvp:
		pvp.Run(*path)
	default:
		panic(fmt.Sprintf("path:%v agrs err", path))
	}
}
